<?php
    // phpinfo();
    // need validate user input data
    $tireqty = $_POST['tireqty'];
    $oilqty = $_POST['oilqty'];
    $sparkqty = $_POST['sparkqty'];

    define('TIREPRICE', 100);
    define('OILPRICE', 10);
    define('SPARKPRICE', 4);
?>

<html>
<head>
    <title>Bob's Auto Parts - Order Results</title>
</head>

<body>
    <h1>Bob's Auto Parts</h1>
    <h2>Order Results</h2>
    <?php 
        echo '<p>Order processed.</p>';
        echo '<p>Order Processed at '.date('H:i, jS F Y').'</p>';

        $totalqty = 0;
        $totalqty = $tireqty + $oilqty + $sparkqty;
        $totalamount = 0.00;

        $totalamount = $tireqty * TIREPRICE
                     + $oilqty * OILPRICE
                     + $sparkqty * SPARKPRICE;

        $taxrate = 0.10;
        $totalamount = $totalamount * (1 + $taxrate);

        if ($totalqty == 0) {
            echo '<p style="color:red">';
            echo 'You did not order anything on the previous page!';
            echo '</p>';
            exit();
        } else {
            echo '<p>Your order is as follows: </p>';
            echo $tireqty.' tires<br />';
            echo $oilqty.' bottles of oil<br />';
            echo $sparkqty.' spark plugs<br />';
        }

        echo "Items ordered: ".$totalqty."<br />";

        echo "Subtotal: $".number_format($totalamount, 2)."<br />";

        echo "Total including tax: $".number_format($totalamount, 2)."<br />";

        switch($_POST['find']) {
            case 'a':
                echo "<p>Regular customer.</p>";
                break;
            case 'b':
                echo "<p>Customer referred by TV advert.</p>";
                break;
            case 'c':
                echo "<p>Customer referred by phone directory.</p>";
                break;
            case 'd':
                echo "<p>Customer referred by word of mouth.</p>";
                break;
            default:
                echo "<p>We do not know how this customer found us.</p>";
                break;
        }

        $testvar = 45;
        echo gettype($testvar);
        settype($testvar, 'double');
        echo gettype($testvar);

        echo strval($testvar);
    ?>
</body>
</html>
